package com.hstc.controller;


import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatClientController {
//    private final ChatClient chatClient;
//
//    private ChatClientController(ChatModel chatModel){
//        this.chatClient = ChatClient.builder(chatModel).build();
//    }
    @Resource
    private  ChatClient chatClient;

    @GetMapping("/chatclient/dochat")
    public String doChat(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return chatClient.prompt()
                .user(msg)
                .call()
                .content();
    }

    @GetMapping("/chatclient/streamchat")
    public Flux<String> streamChat(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return chatClient.prompt()
                .user(msg)
                .stream()
                .content();
    }
}
